<?php


require_once( "_inc.php" );
$siteId = !empty( $_GET['sId'] ) ? intval( $_GET['sId'] ) : "";
$backUrl = !empty( $_GET['back'] ) ? trim( $_GET['back'] ) : "";
if ( empty( $siteId ) )
{
	header( "location: site_list.php" );
	exit( );
}
if ( !empty( $_GET['btnSubmit'] ) )
{
	util::auth( );
	$name = !empty( $_GET['name'] ) ? trim( $_GET['name'] ) : "";
	$color = !empty( $_GET['color'] ) ? trim( $_GET['color'] ) : "";
	$url = !empty( $_GET['url'] ) ? trim( $_GET['url'] ) : "";
	$categoryId = !empty( $_GET['categoryId'] ) ? trim( $_GET['categoryId'] ) : "";
	$isRecommend = !empty( $_GET['isRecommend'] ) ? trim( $_GET['isRecommend'] ) : "0";
	$order = !empty( $_GET['order'] ) ? trim( $_GET['order'] ) : "1000";
	$expireTime = !empty( $_GET['expireTime'] ) ? trim( $_GET['expireTime'] ) : "0";
	$description = !empty( $_GET['description'] ) ? trim( $_GET['description'] ) : "";
	$clickIn = !empty( $_GET['clickIn'] ) ? trim( $_GET['clickIn'] ) : "0";
	$clickOut = !empty( $_GET['clickOut'] ) ? trim( $_GET['clickOut'] ) : "0";
	$clickScore = !empty( $_GET['clickScore'] ) ? trim( $_GET['clickScore'] ) : "0";
	if ( empty( $name ) || empty( $url ) || empty( $categoryId ) )
	{
		$tpl->assign( "msg", "缺少参数。" );
		$tpl->display( "_msg.tpl" );
		exit( );
	}
	if ( !empty( $expireTime ) )
	{
		$expireTime = strtotime( $expireTime );
	}
	$sql = "UPDATE ".$gDb['prefix'].( "sites SET f_name='".$name."', f_color='{$color}', f_url='{$url}', f_categoryId='{$categoryId}', f_isRecommend='{$isRecommend}', f_order='{$order}', f_expireTime='{$expireTime}', f_description='{$description}', f_clickIn='{$clickIn}', f_clickOut='{$clickOut}', f_clickScore='{$clickScore}' WHERE (f_id='{$siteId}')" );
	$db->query( $sql );
	if ( !empty( $backUrl ) )
	{
		header( "location: ".base64_decode( $backUrl ) );
		exit( );
	}
	header( "location: site_list.php" );
	exit( );
}
$tpl->assign( "siteId", $siteId );
$tpl->assign( "backUrl", $backUrl );
$tpl->display( );
?>
